import api from "../../utils/api_util";
import baseUtil from "../../utils/base_util";

var app = getApp();
Page({
    data: {
        StatusBar: app.globalData.StatusBar,
        CustomBar: app.globalData.CustomBar,
        //翻页参数
        page: 1,
        size: 10,
        //分类列表
        firstType: [],
        secondType: [],
        // //父级id
        // parentId:'',
        //布局计算
        // leftHeight: '',
        rightHeight: '',
        windowHeight: '',
        curNav: 1,

        typeFirstName:'',
    },
    onLoad() {
        let windowHeight = wx.getSystemInfoSync().windowHeight;
        // var  leftHeight = this.data.ClassifyList.length * 50;
        this.setData({
            // leftHeight:  leftHeight <=  windowHeight - 40 ?  windowHeight - 40 :  leftHeight,
            windowHeight: windowHeight
        });
        // this.switchRightTab();
        this.getParentType();
    },
    //事件处理函数
    switchRightTab: function (e) {
        let id = e ? e.currentTarget.dataset.id : this.data.firstType[0].id,
            index = e ? parseInt(e.currentTarget.dataset.index) : 0,
            name =e.currentTarget.dataset.name;
        console.log("分类名称：",name)
        this.getSecondType(id);
        this.setData({
            curNav: index,
            typeFirstName: name,
        })
    },
    getParentType() {
        let that = this;
        api.wxRequest.apiRequest(that, api.urls.goodsCategoryList, {
            method: 'GET',
            data: {
                pageSize: 300,
                pageNumber: 1,
                parentId: 0,
            },
            success: function (res) {
                that.getSecondType(res.data.records[0].id);
                that.setData({
                    firstType: res.data.records,
                    typeFirstName: res.data.records[0].name,
                })
            },
        })
    },
    getSecondType(id) {
        let that = this;
        api.wxRequest.apiRequest(that, api.urls.goodsCategoryList, {
            method: 'GET',
            data: {
                pageSize: 300,
                pageNumber: 1,
                parentId: id,
            },
            success: function (res) {
                that.setData({
                    secondType: res.data.records
                })
            },
        })
    },
    getShopList:function (e) {
        let id =  e.currentTarget.dataset.id;
        let that =this;
        baseUtil.pageJump('../ShopList/ShopList?categoryId='+id+'&jumpType=category&name='+that.data.typeFirstName,false);
    }
})